package at.ac.tuwien.lsds.util;

import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.List;

public class ProcessSummaryOutputFile implements OutputFile{

	private List<ProcessSummaryOutputRow> rowList = new ArrayList<ProcessSummaryOutputRow>();
	
	private DecimalFormat df = new DecimalFormat(Settings.getDecimalFormat());
	
//	private ProcessSummaryOutputFile instance = null;
	
//	public ProcessSummaryOutputFile getInstance(){ //TODO: wozu brauchen wir das?
//		if(null == instance){
//			instance = new ProcessSummaryOutputFile();
//		}
//		
//		return instance;
//	}
	
	@Override
	public List<String> getContentRows() {
		List<String> stringRowList = new ArrayList<String>();
		
		for (ProcessSummaryOutputRow row : rowList) {
			String out = "";
			out += row.getScheduler();
			out += Settings.getSeparator() + row.getScenario();
			out += Settings.getSeparator() + row.getTotalPMs().toString();
			out += Settings.getSeparator() + row.getTotalVMs().toString();
			out += Settings.getSeparator() + row.getTotalDuration().toString();
			out += Settings.getSeparator() + df.format(row.getTotalPowerConsumption());
			out += Settings.getSeparator() + row.getTotalInSourced().toString();
			out += Settings.getSeparator() + row.getTotalOutSourced().toString();
			stringRowList.add(out);
		}
		return stringRowList;
	}
	
	@Override
	public String getHeadline() {
		return "Scheduler"+Settings.getSeparator()+"Scenario"+Settings.getSeparator()+"TotalPMs"+Settings.getSeparator()+"TotalVMs"+Settings.getSeparator()+"TotalDuration (ms)"+Settings.getSeparator()+"TotalPowerConsumption (W)"+Settings.getSeparator()+"TotalInSourced"+Settings.getSeparator()+"TotalOutSourced";
	}	
	
	@Override
	public String getFilePath() {
		return Settings.getProcessSummaryOutputFilePath();
	}

	public void addRow(ProcessSummaryOutputRow row) {
		if(row != null)
			rowList.add(row);
	}
	
}
